(function(window, undefined) {


  let t = null

  $.fn.lazyLoad = function() 
  {
    let _this = this  
    function lazyLoad() 
    {
      if (t) clearTimeout(t)
      t = setTimeout(() => {
      //    2.1 获取可视区高度
        let windowH = window.innerHeight || document.documentElement.clientHeight
        let scrollH = document.body.scrollTop || document.documentElement.scrollTop
        let showH = windowH + scrollH
      //    2.2 获取所有图片
        // let imgs = document.querySelectorAll('.lazy')
        let imgs = _this
      //    2.3 遍历  判断 
        for (let i=0; i<imgs.length; i++)
        {
            if (imgs[i].offsetTop < showH) {
              imgs[i].src = imgs[i].getAttribute('data-src')
            }
        }
      }, 100)
    }
  
    lazyLoad()
    window.onscroll = lazyLoad
  }
  
})(window)